package com.tssm.core.util;

public class Pages {
	
	private int currentPage; // 当前页
	private int pageCount; // 总页数
	private int pageSize; // 每页显示条数
	private int firstIndex;//开始查询的条数
	private int allNum; // 总条数
	
	public void setPages(final int allNum, final int pageSize) {
		this.allNum = allNum;
		this.pageSize = pageSize;
		if(currentPage == 0) currentPage = 1;
		if (allNum == 0) {
			pageCount = 1;
		} else {
			pageCount = (int) Math.ceil((double) allNum / pageSize);
		}
		firstIndex = (currentPage - 1) * pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getFirstIndex() {
		return firstIndex;
	}

	public void setFirstIndex(int firstIndex) {
		this.firstIndex = firstIndex;
	}

	public int getAllNum() {
		return allNum;
	}

	public void setAllNum(int allNum) {
		this.allNum = allNum;
	}

	/**
	 * 
	 * 
	 * @方法说明: 删除i条记录后跳转的页号
	 * @param i
	 * @param currentPage
	 * @return
	 * @作者:徐龙
	 * @日期:2011-5-17
	 */
	public int getDelPage(int i, int currentPage) {
		int allNum = this.allNum + i;
		int p;
		if ((allNum - i) <= 0) {
			p = 1;
		} else {
			p = (int) Math.ceil((double) (allNum - i) / pageSize);
		}
		return (currentPage - p) < 0 ? currentPage : p;
	}


}
